Attribute VB_Name = "modReadWriteMail"
Public esmtp As String
Public eyourname As String
Public email As String
Public bAuthLogin      As Boolean
Public eusername As String
Public epassword As String
Public esubject As String
Public emessage As String
Public eport As String

Public Function ReadTextFile(strPath As String)
    ' Get a free file number
    nFileNum = FreeFile
    Dim sText As String
    ' Open a text file for input. inputbox returns the path to read the file
    Open strPath For Input As nFileNum
        'lLineCount = 1
        ' Read the contents of the file
        Do While Not EOF(nFileNum)
            Line Input #nFileNum, sNextLine
            If sNextLine = "[SMTP]" Then
                Line Input #nFileNum, sNextLine
                While sNextLine <> "[PORT]"
                    esmtp = Trim(sNextLine)
                    Line Input #nFileNum, sNextLine
                Wend
            End If
            If sNextLine = "[PORT]" Then
                Line Input #nFileNum, sNextLine
                While sNextLine <> "[YOURNAME]"
                    eport = Trim(sNextLine)
                    Line Input #nFileNum, sNextLine
                Wend
            End If
            If sNextLine = "[YOURNAME]" Then
                Line Input #nFileNum, sNextLine
                While sNextLine <> "[EMAILADDRESS]"
                    eyourname = Trim(sNextLine)
                    Line Input #nFileNum, sNextLine
                Wend
            End If
            If sNextLine = "[EMAILADDRESS]" Then
                Line Input #nFileNum, sNextLine
                While sNextLine <> "[AUTHENTICATION]"
                    email = Trim(sNextLine)
                    Line Input #nFileNum, sNextLine
                Wend
            End If
            If sNextLine = "[AUTHENTICATION]" Then
                Line Input #nFileNum, sNextLine
                While sNextLine <> "[USERNAME]"
                    bAuthLogin = Trim(sNextLine)
                    Line Input #nFileNum, sNextLine
                Wend
            End If
            If sNextLine = "[USERNAME]" Then
                Line Input #nFileNum, sNextLine
                While sNextLine <> "[PASSWORD]"
                    eusername = Trim(sNextLine)
                    Line Input #nFileNum, sNextLine
                Wend
            End If
            If sNextLine = "[PASSWORD]" Then
                Line Input #nFileNum, sNextLine
                While sNextLine <> "[SUBJECT]"
                    epassword = Trim(sNextLine)
                    Line Input #nFileNum, sNextLine
                Wend
            End If
            If sNextLine = "[SUBJECT]" Then
                Line Input #nFileNum, sNextLine
                While sNextLine <> "[MESSAGE]"
                    esubject = Trim(sNextLine)
                    Line Input #nFileNum, sNextLine
                Wend
            End If
            If sNextLine = "[MESSAGE]" Then
                Line Input #nFileNum, sNextLine
                emessage = ""
                Do While Not EOF(nFileNum)
                    emessage = Trim(emessage) & Trim(sNextLine) & Chr$(13) + Chr$(10)
                    Line Input #nFileNum, sNextLine
                Loop
                emessage = emessage & Trim(sNextLine)
            End If
        Loop
        ' Close the file
    Close nFileNum
    'ReadTextFile = sText
End Function

Public Function WriteTextFile(strPath As String)
    Open strPath For Output As #1 'nFileNum
        Print #1, "[SMTP]"
        Print #1, esmtp
        Print #1, "[PORT]"
        Print #1, eport
        Print #1, "[YOURNAME]"
        Print #1, eyourname
        Print #1, "[EMAILADDRESS]"
        Print #1, email
        Print #1, "[AUTHENTICATION]"
        Print #1, bAuthLogin
        Print #1, "[USERNAME]"
        Print #1, eusername
        Print #1, "[PASSWORD]"
        Print #1, epassword
        Print #1, "[SUBJECT]"
        Print #1, esubject
        Print #1, "[MESSAGE]"
        Print #1, emessage
        ' Close the file
    Close #1
End Function
